package com.qiangou.ti;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.io.IOUtils;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.zip.GZIPInputStream;

public class GetCart {


    @Test
    public void testCart() throws IOException {
        System.out.println("-------  testCart   请求来了~~~    -------");


        // 请求地址
        String url = "https://www.ti.com.cn/store/ti/zh/cart?contShopUrl=https://www.ti.com.cn/store/ti/zh/cart?contShopUrl=https%3A%2F%2Fwww.ti.com.cn%2Fstore%2Fti%2Fzh%2Fp%2Fproduct%2F%3Fp%3DAMC1336EVM&_ticdt=MTYzOTU2ODAyM3wwMTdkNzRmMTE5M2QwMDAxZTFmNGFkZWY3OWY1MDUwNzEwMTI1MDY5MDBiZDB8R0ExLjMuNjY2NjY2MTg0LjE2MzgzNDQ0MDg&_ticdt=MTYzOTU2ODU5MXwwMTdkNzRmMTE5M2QwMDAxZTFmNGFkZWY3OWY1MDUwNzEwMTI1MDY5MDBiZDB8R0ExLjMuNjY2NjY2MTg0LjE2MzgzNDQ0MDg";
        HttpClient client = new HttpClient();

        // post请求方式

        GetMethod getMethod = new GetMethod(url);


        getMethod.addRequestHeader("Content-Type", "text/html; charset=UTF-8");

        getMethod.setRequestHeader(":authority", "www.ti.com.cn");
        getMethod.setRequestHeader(":method", "GET");
        getMethod.setRequestHeader(":path", "/store/ti/zh/cart?contShopUrl=https://www.ti.com.cn/store/ti/zh/cart?contShopUrl=https%3A%2F%2Fwww.ti.com.cn%2Fstore%2Fti%2Fzh%2Fp%2Fproduct%2F%3Fp%3DAMC1336EVM&_ticdt=MTYzOTU2ODAyM3wwMTdkNzRmMTE5M2QwMDAxZTFmNGFkZWY3OWY1MDUwNzEwMTI1MDY5MDBiZDB8R0ExLjMuNjY2NjY2MTg0LjE2MzgzNDQ0MDg&_ticdt=MTYzOTU2ODU5MXwwMTdkNzRmMTE5M2QwMDAxZTFmNGFkZWY3OWY1MDUwNzEwMTI1MDY5MDBiZDB8R0ExLjMuNjY2NjY2MTg0LjE2MzgzNDQ0MDg");
        getMethod.setRequestHeader(":scheme", "https");
        getMethod.setRequestHeader("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
        getMethod.setRequestHeader("accept-encoding", "gzip, deflate, br");
        getMethod.setRequestHeader("accept-language", "zh-CN,zh;q=0.9");
        getMethod.setRequestHeader("cookie", "ti-cart=8985c058-7674-4445-aaa3-916267c4396a; JSESSIONID=2262CED9E2ABD7683EBCF3D1ABE05650.store-prod-hybris2; ti_ua=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4662.6 Safari/537.36; user_pref_language=\"zh-CN\"; CONSENTMGR=ts:1638344407862|consent:true; _ga=GA1.3.666666184.1638344408; _gcl_au=1.1.503510175.1638344410; _fbp=fb.2.1638344410324.289473467; __adroll_fpc=4c2200562bfaf1cd781880af5863e15b-1638344410975; ELOQUA=GUID=5D3E7DAEE7984587B552787F903E7B2D; tiSessionID=017d74f1193d0001e1f4adef79f505071012506900bd0; login-check=null; login-check=null; user_pref_shipTo=\"CN\"; user_pref_currency=\"CNY\"; coveo_visitorId=606b89f2-3603-4408-9e28-6ba52656f544; ti_bm=; _gid=GA1.3.31299235.1639392521; ti_geo=country=CN|city=GUANGZHOU|continent=AS|tc_ip=116.24.66.223; last-domain=www.ti.com.cn; user_pref_givenNameLocalLanguage=\"泽凯\"; alias=homepageproduct; ti_get_lit=ts=1639554461806|lit=bq76930|pid=|aid=|gpn=Non-Product|pt=search|evt=20211115154741806|; __ar_v4=G3YHLXUICZC3XKDXYVVLO4:20220013:5|2XNKMR6P4VGD5MD3ZP4SQR:20220013:5|QFXRHQEHOJDMLHSLFIWCLO:20220013:5; bm_mi=64E46A5BD9B8A50B63ED8C325B2E299E~F+Tjmo6lysdZ6w6H7lzy7o9S3TRNSlXjKIyksxvXltPmcG7TqMRwYVB9+2RCsG+rah7gdbqbvD+2BkEmxSFSFL/n5X4p0wJe+5yaQQuZKvokzdAmKeM3M79bMzel+YWYDVUEegh9nIbjAb4XH1zm53LOqzWfziKsaElEYQjCIbaSjhn+38VLvDAg1Ku8w0QVTD5iO/1C8hDWUK0KVljI+4c58ZsuSQlAi8Mpyh+EYLqmS6SjBsq9uCzeSDLmaYeQWgPe/Grfs3V7AYSmPB0mAH+aJIevEvYoAw+H/Pf+SnILBq/zTgrp4PqWmnelEKz/; user_pref_permanentId=6917553; user_pref_givenName=; user_pref_uid=gdzk168@outlook.com; acceleratorSecureGUID=376f393fcc5537205bef2127b48a18ccec9d2c7b; ticontent=/tistore; tipage=/tistore/shopping cart zh; tipageshort=shopping cart zh; ak_bmsc=44569DB908B5BFC0E15ACF5241D7A3F2~000000000000000000000000000000~YAAQ5G+bG2Wmurl9AQAADoDkvQ6Oe6JEuFgebGzcOfykhZnNI5LqraIlo/EVzp3fgmc8J0/o/oYCnRJ30wqksZbFWlPV11hOMT3p4lIt/xKfLeeoxrlGRT0VCOocXco7PHNRHeM6etV0ufuVwXyNM/jjO2VzHLzLJq7hq/DXkfEfLi/sTtXH2KtTWB8yPf8sfu8PKLBAu2Fvt23iwBCSJMTLirM+Bwmb2ARtBVEGAcsR1JuYRkzregVPNkX7DL+e16k6uaYJBwsTWfK4LBX7S/O4ZH0nBlMJxYCVlncWk/1E/DjmbZq+T6Ticl5wXZtNNUrvEsVmfiJvElmfO8Cepl5D8yzPfiLNTasU5/yyljm8JnQizcA4Xoj3DyY62L5Ie/Is64eUKvRaPg1AH1awh+waBaD7zRerxAeVC9Wds6Izq2kl/9eNU6wocUriSR4ut/d8xv5/HSHwe9I7WboLOYQdrGLw+6AFLKTAms/NlPDCQjbXXrZ6noVGJQt0HRQ40Qtk8NeAGeIzcFz6xvhA4e0=; sec_cpt=11590E633746916B2F0D6C99509FB1AF~4~YAAQ5G+bGy7Ourl9AQAABVzlvQYtjYVxj18AnzHtCsnpfqLDOS1isWmJo4yPaTCEMqP4fm5N4SWZQJOWXDtHhEZDHmW4DCBsdMY0E8iOMWdS1H4GRjAG6YrgiDs90Vcnepjp3ZWBx5dwyq+tun6Iwr6dYFruejHiyVEtiOo0TonlzfUF/nAdTxWxtmev64UIxHUETdhcF9awzUedo3FnNfMGByNUh5SemGNlDRiJVUsIXvdsjV05VIHY3nPSBDvTTUOds4iAkOyuK0NYGRBvsPCozBOAsD3Z3h76CcNPchFr5DRcxtH8oERGjk2a10oV/0VTtGzm/t6O1d/bLBc6EOqbCsk2AHvDknkFbc8LopuVQ5M0sT7VU5hRtshVaP0hwpmx8vJuZPsoDtoKjQXn48Xo5DcehdKlkxFrQzV8E3IADZziEmRdVjx4I1TApY8IAjq9P900cYU+EwlCSDjuc5WBD3g8LM09DwukrkNihBrJ0ywE+F9s3iGof1CDF7gcmfpWPgGTqYooS9DifTR4rQNeMx4AZpOVQh3p1zJ9MYsHC7cD1jMRW7tVoy+bnEVEUg==; ga_page_cookie=shopping cart zh; ga_content_cookie=/tistore; ABTasty=uid=vypwvnt3c01qrsxa&fst=1639485229472&pst=1639553042804&cst=1639566780445&ns=3&pvt=29&pvis=6&th=686831.851794.12.5.3.1.1639485250594.1639568466208.1; ABTastySession=mrasn=&sen=15&lp=https%3A%2F%2Fwww.ti.com.cn%2Fstore%2Fti%2Fzh%2Fcart%3FcontShopUrl%3Dhttps%3A%2F%2Fwww.ti.com.cn%2Fproduct%2Fcn%2FSN6501%23order-quality%26_ticdt%3DMTYzOTU2Njc1NXwwMTdkNzRmMTE5M2QwMDAxZTFmNGFkZWY3OWY1MDUwNzEwMTI1MDY5MDBiZDB8R0ExLjMuNjY2NjY2MTg0LjE2MzgzNDQ0MDg; da_sid=2EBC23818E32AE89DF07AA1349EBB3B883|4|0|3; da_intState=; da_lid=1D8F10B29A73EA12815BBB990B20DDA568|0|0|0; userType=Anonymous; _gat_ga_main_tracker=1; _abck=96110CECF7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WB00ECd3P4Bi9Th0YMESsWPF2YgRashCG11PaE+HLA10BhVlRunvH6jU0QaCeJN5+4WHtvkiqzMq0lew68eGb82nKmCXdi0nTgdRwPhNLjn/c5bzWbozPihFo7JOdHZktIVT4GwTmYD0deAwrrin2yZgifr0v4=; utag_main=free_trial:false$_st:1639570391484$v_id:017db8ef47bc007120575ddec7a805071005206900bd0$_sn:3$_ss:0$dc_visit:3$_pn:6;exp-session$ses_id:1639566780183;exp-session$dc_event:4;exp-session$dc_region:ap-east-1;exp-session; samlPassThroughToken=\"1:HCgYbTIUVHhyf0i2oiErXQ==QlXxDN7vzqkL+wamaeeiKax1E5ZR6JrARiPCnL36K/7wjV4SG3MsOfkeiF2D5FsPxsdrDyXMOT0z 414RAWQPgg==\"; ti_rid=2cc9968");
        getMethod.setRequestHeader("referer", "https://www.ti.com.cn/store/ti/zh/cart?contShopUrl=https://www.ti.com.cn/store/ti/zh/p/product/?p=AMC1336EVM&_ticdt=MTYzOTU2ODAyM3wwMTdkNzRmMTE5M2QwMDAxZTFmNGFkZWY3OWY1MDUwNzEwMTI1MDY5MDBiZDB8R0ExLjMuNjY2NjY2MTg0LjE2MzgzNDQ0MDg");
        getMethod.setRequestHeader("sec-ch-ua", "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"96\", \"Google Chrome\";v=\"96\"");
        getMethod.setRequestHeader("sec-ch-ua-mobile", "?0");
        getMethod.setRequestHeader("sec-ch-ua-platform", "\"Windows\"");
        getMethod.setRequestHeader("sec-fetch-dest", "document");
        getMethod.setRequestHeader("sec-fetch-mode", "navigate");
        getMethod.setRequestHeader("sec-fetch-site", "same-origin");
        getMethod.setRequestHeader("sec-fetch-user", "?1");
        getMethod.setRequestHeader("upgrade-insecure-requests", "1");
        getMethod.setRequestHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4662.6 Safari/537.36");


        client.executeMethod(getMethod);

        InputStream in = getMethod.getResponseBodyAsStream();

        //这里的编码规则要与上面的相对应
        System.out.println("############################");
        // getMethod.setRequestHeader("accept-encoding", "gzip, deflate, br"); 服务器可能会用gzip压缩。 实际上压缩了， 这里需要解压缩
        System.out.println(IOUtils.toString(new GZIPInputStream(in),"UTF-8"));
    }


}
